<%@ page import="java.text.NumberFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="com.nus.beans.User" %>
<%@ page import="java.util.List" %>
<%@ page import="com.nus.beans.UserType" %>
<%@ page import="com.nus.beans.Project" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="com.nus.beans.ProjectStatus" %>
<%@ page import="org.apache.commons.lang3.StringEscapeUtils" %>
<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 9/21/12
  Time: 12:10 AM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>Update Project</title></head>
<body>
<%
    Project project = (Project) request.getAttribute("project");
    List<User> assigneesList = (List<User>) request.getAttribute("assigneesList");
    List<User> eligibleUser = (List<User>) request.getAttribute("eligibleUser");
    int year, month, dateofMonth;
    String errorMessage = (String) request.getAttribute("ERROR_MESSAGE");
%>

<table>
<form method="post" action="updateProject.do">
<input type="hidden" name="id" value="<%=project.getId()%>"/>
<tr>
    <td>Project Name:</td>
    <td><input type="text" name="projectName" value="<%=StringEscapeUtils.escapeXml(project.getProjectName())%>" maxlength="50"/></td>
</tr>

<tr>
    <td>Project Status:</td>
    <td><select name="projectStatus">
        <% for (ProjectStatus projectStatus : ProjectStatus.values()) { %>
        <% if (projectStatus.equals(project.getStatus())) {%>
        <option value="<%=projectStatus%>" selected="true">
                <% } else { %>
        <option value="<%=projectStatus%>">
            <% } %>
            <%=projectStatus%>
        </option>
        <% } %>

    </select></td>
</tr>

<%
    Date date = project.getStartingDate();
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);

    year = calendar.get(Calendar.YEAR);
    month = calendar.get(Calendar.MONTH) + 1;
    dateofMonth = calendar.get(Calendar.DATE);
    System.out.println("month = " + project.getStartingDate());

%>


<tr>
    <td>Start Date:</td>
    <td><select name="startYear">
        <%for (int i = 2000; i < 2100; i++) {%>
        <% if (i == year) { %>
        <option value="<%=i%>" selected="true">
                <% } else { %>
        <option value="<%=i%>">
            <% } %>


            <%=i%>
        </option>
        <%}%>
    </select>

        <select name="startMonth">
            <%for (int j = 1; j < 13; j++) {%>
            <% if (j == month) { %>
            <option value="<%=j%>" selected="true">
                    <% } else { %>
            <option value="<%=j%>">
                <% } %>


                <%=j%>
            </option>
            <%}%>
        </select>
        <select name="startDate">
            <%for (int k = 1; k < 32; k++) {%>
            <% if (k == dateofMonth) { %>
            <option value="<%=k%>" selected="true">
                    <% } else { %>
            <option value="<%=k%>">
                <% } %>


                <%=k%>
            </option>
            <%}%>
        </select>
    </td>
</tr>


<%
    date = project.getEstimatedEndDate();
    calendar = Calendar.getInstance();
    calendar.setTime(date);

    year = calendar.get(Calendar.YEAR);
    month = calendar.get(Calendar.MONTH) + 1;
    dateofMonth = calendar.get(Calendar.DATE);

%>

<tr>
    <td>Estimated End Date:</td>
    <td><select name="endYear">
        <%for (int i = 2000; i < 2100; i++) {%>
        <% if (i == year) { %>
        <option value="<%=i%>" selected="true">
                <% } else { %>
        <option value="<%=i%>">
            <% } %>


            <%=i%>
        </option>
        <%}%>
    </select>

        <select name="endMonth">
            <%for (int j = 1; j < 13; j++) {%>
            <% if (j == month) { %>
            <option value="<%=j%>" selected="true">
                    <% } else { %>
            <option value="<%=j%>">
                <% } %>


                <%=j%>
            </option>
            <%}%>
        </select>
        <select name="endDate">
            <%for (int k = 1; k < 32; k++) {%>
            <% if (k == dateofMonth) { %>
            <option value="<%=k%>" selected="true">
                    <% } else { %>
            <option value="<%=k%>">
                <% } %>


                <%=k%>
            </option>
            <%}%>
        </select>
    </td>
</tr>

<%
    date = project.getDeadline();
    calendar = Calendar.getInstance();
    calendar.setTime(date);

    year = calendar.get(Calendar.YEAR);
    month = calendar.get(Calendar.MONTH) + 1;
    dateofMonth = calendar.get(Calendar.DATE);

%>


<tr>
    <td>Deadline:</td>
    <td><select name="deadlineYear">
        <%for (int i = 2000; i < 2100; i++) {%>
        <% if (i == year) { %>
        <option value="<%=i%>" selected="true">
                <% } else { %>
        <option value="<%=i%>">
            <% } %>


            <%=i%>
        </option>
        <%}%>
    </select>

        <select name="deadlineMonth">
            <%for (int j = 1; j < 13; j++) {%>
            <% if (j == month) { %>
            <option value="<%=j%>" selected="true">
                    <% } else { %>
            <option value="<%=j%>">
                <% } %>


                <%=j%>
            </option>
            <%}%>
        </select>
        <select name="deadlineDate">
            <%for (int k = 1; k < 32; k++) {%>
            <% if (k == dateofMonth) { %>
            <option value="<%=k%>" selected="true">
                    <% } else { %>
            <option value="<%=k%>">
                <% } %>


                <%=k%>
            </option>
            <%}%>
        </select>
    </td>
</tr>
<tr>
    <td>Select User:</td>
    <td>
        <table>
            <%
                for (User user : eligibleUser) {%>
            <tr>
                <td><input type="checkbox" name="<%= "user_" + user.getUserId() %>"
                           value="<%=user.getUserId()%>"
                        <% if(assigneesList.contains(user)){ %>
                            checked="true"
                        <% } %>
                        /></td>
                <td><%=StringEscapeUtils.escapeXml(user.getFirstName()) + " " + StringEscapeUtils.escapeXml(user.getLastName()) + "       " + user.getUserType().toString()%>
                </td>
            </tr>
            <% } %>
        </table>
    </td>
</tr>
<tr><td colspan="2">
    <% if(errorMessage != null){ %>
            <%=errorMessage%>
    <% } %>
</td></tr>
<tr><td colspan="2">
    <input type="submit" value="Update"/>
<a href="viewHome.do">Home</a>
</td></tr>

</form>
</table>

</body>
</html>